﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using System.Configuration;

namespace 医院药库管理系统
{
    public partial class 厂商资料查询 : Form
    {
        public 厂商资料查询()
        {
            InitializeComponent();
        }

        private void bt_cscxfh_Click(object sender, EventArgs e)
        {
            首页 f3 = new 首页();
            f3.Show();
        }

        private void bt_qd_Click(object sender, EventArgs e)
        {
            SqlConnection sqlConnection = new SqlConnection();
            sqlConnection.ConnectionString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;                             //在字符串变量中，描述连接字符串所需的服务器地址、数据库名称、集成安全性（即是否使用Windows验证）；
            SqlCommand sqlCommand = new SqlCommand();                                                       //声明并实例化SQL命令；
            sqlCommand.Connection = sqlConnection;                                                          //将SQL命令的连接属性指向SQL连接；
            sqlCommand.CommandText = "SELECT * FROM tb_firm WHERE Name LIKE '%'+@Name+'%';";                              //指定SQL命令的命令文本；
            sqlCommand.Parameters.AddWithValue("@Name", this.cb_csmc.Text.Trim());                                        //向SQL命令的参数集合添加参数的名称、值；
            SqlDataAdapter sqlDataAdapter = new SqlDataAdapter();
            sqlDataAdapter.SelectCommand = sqlCommand;
            DataTable csTable = new DataTable();
            sqlConnection.Open();
            sqlDataAdapter.Fill(csTable);
            sqlConnection.Close();
            this.dgv_cscx.DataSource = csTable; 
            
        }

        private void 厂商资料查询_Load(object sender, EventArgs e)
        {
            // TODO: 这行代码将数据加载到表“yyaoDataSet7.tb_Firm”中。您可以根据需要移动或移除它。
            this.tb_FirmTableAdapter1.Fill(this.yyaoDataSet7.tb_Firm);
            
            SqlConnection sqlConnection = new SqlConnection();
            sqlConnection.ConnectionString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString; 
            SqlCommand sqlCommand = new SqlCommand();
            sqlCommand.Connection = sqlConnection;
            sqlCommand.CommandText = "SELECT * FROM tb_Firm;";
            SqlDataAdapter sqlDataAdapter = new SqlDataAdapter();
            sqlDataAdapter.SelectCommand = sqlCommand;
            DataTable csTable = new DataTable();
            sqlConnection.Open();
            sqlDataAdapter.Fill(csTable);
            sqlConnection.Close();
            this.dgv_cscx.DataSource = csTable;
            this.dgv_cscx.Columns["No"].HeaderText = "编号";
            this.dgv_cscx.Columns["Name"].HeaderText = "名称";
            this.dgv_cscx.Columns["Attribution"].HeaderText = "归属地";
        }

        private void cb_csmc_SelectedIndexChanged(object sender, EventArgs e)
        {

        }      
    }
}
